package big;

import java.text.DecimalFormat;

abstract class Shape{

    protected abstract double getArea();
}

class Circle extends Shape{

    private int r;

    public Circle(int r) {
        this.r = r;
    }

    @Override
    protected double getArea() {
        return Math.PI*r*r;
    }
}
public class DecimalFormatDemo {

    public static void main(String[] args) {
        double price = 1500000;
        double percent = 0.00789;
        Shape circle = new Circle(10);
        System.out.println("面积是："+circle.getArea());

        DecimalFormat df = new DecimalFormat("#####.00");//小数点后保留两位
        System.out.println("面积是："+df.format(circle.getArea()));
        df = new DecimalFormat("0.##E0");//科学计数法
        System.out.println("面积是："+df.format(circle.getArea()));
        df = new DecimalFormat("###,###,###.00");//千分位表示
        System.out.println("价格是：" + df.format(price));
        df = new DecimalFormat("\u00A4###,###,###.00");//添加货币符号
        System.out.println("价格是：" + df.format(price));
        df = new DecimalFormat("#0.00\u2030");//千分比表示
        System.out.println("比率是：" + df.format(percent));
    }
}
